<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>I2C_BB_Write Function</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="generator" content="Doc-O-Matic" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="STYLESHEET" href="default.css" type="text/css" />

<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('frames.html', 'topic', '00601.html');" onmousedown="onBodyMouseDown();">

<!-- Begin Popups -->

<!-- End Popups -->

<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element94">
<a href="00675.html" target="topic">Software Libraries Help</a> &gt; <a href="00591.html" target="topic">I2C Bit Bang Library Help</a> &gt; <a href="00592.html" target="topic">Library Interface</a> &gt; c) Transaction Functions &gt; <a href="00601.html" target="topic">I2C_BB_Write Function</a></div>
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element1">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element2">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element90">
<a href="00600.html" target="topic">Previous</a> | <a href="00592.html" target="topic">Up</a> | <a href="00602.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element96">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: I2C_BB_Write@uint16_t@uint8_t *@size_t Topic Title: I2C_BB_Write Function)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table><div class="Element5">
I2C_BB_Write Function</div>
</div>
</div>

<!-- End Page Header -->

<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">

<!-- Begin Page Content -->
<a name="PageContent"></a><div class="Element58">
<a name="4465736372697074696F6E"></a><div class="Element11">
<div class="Element10">
<p class="Element10">
This function writes data to a slave on the bus. The function will attempt to write length number of bytes from pdata buffer to a slave whose address is specified by address. The I2C Master will generate a Start condition, write the data and then generate a Stop Condition. If the slave NAKs the request the transfer is terminated. The application can call the <a href="00598.html" target="topic">I2C_BB_ErrorGet</a>() function to know that cause of the error.&nbsp;</p>
<p class="Element10">
The function is non-blocking. It initiates bus activity and returns immediately. The transfer is then completed in the timer peripheral interrupt. A transfer request cannot be placed when another transfer is in progress. Calling the write function when another function is already in progress will cause the function to return false.&nbsp;</p>
<p class="Element10">
The library will call the registered callback function when the transfer has terminated.</p></div>
</div>
<a name="43"></a><div class="Element99">
C</div>
<div class="Element101"><div class="Element100"><pre class="Element100"><strong><span style="color: #000080">bool</span></strong> <strong><span style="color: #000000">I2C_BB_Write</span></strong>(
    uint16_t <strong><span style="color: #000000">address</span></strong>, 
    uint8_t * <strong><span style="color: #000000">pdata</span></strong>, 
    size_t <strong><span style="color: #000000">length</span></strong>
);</pre></div></div>
<a name="507265636F6E646974696F6E73"></a><div class="Element14">
Preconditions</div>
<div class="Element11">
<div class="Element10">
<p class="Element10">
<a href="00599.html" target="topic">I2C_BB_Initialize</a> must have been called for the associated I2C instance.</p></div>
</div>
<a name="506172616D6574657273"></a><div class="Element14">
Parameters</div>
<div class="Element11">
<div class="Element10">
<div class="Element312">
<div class="TableDiv">
<table cellspacing="0" class="Table3">
<tr>
<td class="Element300" valign="top" width="35%">
<div class="Element301">
Parameters&nbsp;</div></td><td class="Element304" valign="top" width="65%">
<div class="Element305">
Description&nbsp;</div></td></tr><tr>
<td class="Element302" valign="top" width="35%">
<div class="Element303">
address&nbsp;</div></td><td class="Element306" valign="top" width="65%">
<div class="Element307">
7-bit / 10-bit slave address.<br>&nbsp;</div></td></tr><tr>
<td class="Element302" valign="top" width="35%">
<div class="Element303">
data&nbsp;</div></td><td class="Element306" valign="top" width="65%">
<div class="Element307">
pointer to source data buffer that contains the data to be written.<br>&nbsp;</div></td></tr><tr>
<td class="Element302" valign="top" width="35%">
<div class="Element303">
length&nbsp;</div></td><td class="Element306" valign="top" width="65%">
<div class="Element307">
length of data buffer in number of bytes. Also the number of bytes to be written.&nbsp;</div></td></tr></table></div></div>
</div>
</div>
<a name="52657475726E73"></a><div class="Element14">
Returns</div>
<div class="Element11">
<div class="Element10">
<p class="Element10">
true - The request was placed successfully and the bus activity was initiated.&nbsp;</p>
<p class="Element10">
false - The request fails,if there was already a transfer in progress when this function was called.</p></div>
</div>
<a name="52656D61726B73"></a><div class="Element14">
Remarks</div>
<div class="Element11">
<div class="Element10">
<p class="Element10">
None.</p></div>
</div>
<a name="4578616D706C65"></a><div class="Element14">
Example</div>
<div class="Element11">
<div class="Element10">
<div class="Element13"><div class="Element12"><pre class="Element12">    uint8_t myData [NUM_BYTES];
    <strong><span style="color: #000080">void</span></strong> MyI2CCallback(uintptr_t context)
    {
        <i><span style="color: #008000">// This function will be called when the transfer completes. Note</span></i>
        <i><span style="color: #008000">// that this function executes in the context of the I2C interrupt.</span></i>
    }

    <a href="00599.html" target="topic">I2C_BB_Initialize</a>();
    <a href="00597.html" target="topic">I2C_BB_CallbackRegister</a>(MyI2CCallback, NULL);

    <strong><span style="color: #000080">if</span></strong>(!I2C_BB_Write( SLAVE_ADDR, &amp;myData[0], NUM_BYTES ))
    {
        <i><span style="color: #008000">// error handling</span></i>
    }
</pre></div></div>
</div>
</div>
</div>
<!-- End Page Content -->

<!-- Begin Page Footer -->
<div class="Element95">
<a href="00675.html" target="topic">Software Libraries Help</a> &gt; <a href="00591.html" target="topic">I2C Bit Bang Library Help</a> &gt; <a href="00592.html" target="topic">Library Interface</a> &gt; c) Transaction Functions &gt; <a href="00601.html" target="topic">I2C_BB_Write Function</a></div>
<div class="Element93">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element3">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element4">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element91">
<a href="00600.html" target="topic">Previous</a> | <a href="00592.html" target="topic">Up</a> | <a href="00602.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element97">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: I2C_BB_Write@uint16_t@uint8_t *@size_t Topic Title: I2C_BB_Write Function)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table></div>

<!-- End Page Footer -->
</div>
</div>

<!-- End Client Area -->
</body></html>